import EventMgr from "./EventMgr";
import GameEventType from "./GameEventType";
import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import PageMgr from "./PageMgr";
import UiManage from "./UiManage";
import ReconnectPage from "./ReconnectPage";
const { ccclass, property } = cc._decorator;

@ccclass
export default class ReconnectPageCtrl extends BasePageCtrl {
    @property(ReconnectPage)
    ui: ReconnectPage = null;
    reconnectFun: Function = null;

    onLoad() {
        super.onLoad();
        this.onUILoad();
        this._animType = AnimType.NONE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        this.addButtonListen();
        EventMgr.listen(GameEventType.CLOSE_RECONNECT, this.clickClose, this);
    }

    onUILoad() {
        this.ui = this.node.addComponent(ReconnectPage);
    }

    addButtonListen() {
        UiManage.addButtonListen(this.ui.agree, this.reconnect, this);
    }

    _init(e?) {
        if (e && e.data) {
            const t = e.data.callback;
            this.reconnectFun = t;
        }
    }

    reconnect() {
        const e = this;
        PageMgr.showPage("LoadingPage", {
            name: "LoadingPage",
            data: {
                callback: function () {
                    if (e.reconnectFun) {
                        e.clickClose();
                        e.scheduleOnce(function () {
                            e.reconnectFun(true);
                        }, 0.5);
                    }
                },
            },
        });
    }

    clickClose() {
        this.hide();
    }
}
